package com.tgpms.web.earlierStage.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.tgpms.web.earlierStage.entity.TaskJournal;

/**
* 表TASK_JOURNAL -> null 的基本功能实现
*
* @author DESKTOP-I3TG0H3
* @createDate 2019/11/27
*/
@Mapper
public interface TaskJournalMapper {
	
	List<TaskJournal> getJournalByids();
	
	//获取父类下子任务的百分比之和
	@Select("select NVL(SUM(MAX(t.ratio)),0) from task_journal t where t.id in "
			+ "(select a.id from task_definition a "
			+ "where a.parent_id=#{parentid} and (a.if_ignore is null or a.if_ignore!='1')) "
			+ "group by t.id")
	String getParentRatios(String parentid);
	
	//获取父类下子集的个数
	@Select("select COUNT(ID) from task_definition where PARENT_ID=#{parentid}")
	int getParentCounts(String parentid);
	
	//获取父类下子任务无需办理的百分比之和
	@Select("select (COUNT(ID)*100) from task_definition where PARENT_ID=#{parentid} and IF_IGNORE='1'")
	int getParentYRatios(String parentid);
	
	@Select("select id from task_journal where id=#{id}")
	List<TaskJournal> getTaskJournalByid(String id);
	
	//根据id删除
	@Delete("delete from task_journal where id=#{id}")
	int deleteByid(String id);
	
    /**
     * null  deleteByPrimaryKey 实现
     * 
     * @param journalId
     * @return null int
     * @author: DESKTOP-I3TG0H3
     * @createDate: 2019-11-27 15:31:51
     */
    int deleteByPrimaryKey(@Param("id")String id,@Param("journalId")String journalId);

    /**
     * null  insert 实现
     * 
     * @param record
     * @return null int
     * @author: DESKTOP-I3TG0H3
     * @createDate: 2019-11-27 15:31:51
     */
    int insert(TaskJournal record);

    /**
     * null  insertSelective 实现
     * 
     * @param record
     * @return null int
     * @author: DESKTOP-I3TG0H3
     * @createDate: 2019-11-27 15:31:51
     */
    int insertSelective(TaskJournal record);

    /**
     * null  selectByPrimaryKey 实现
     * 
     * @param id
     * @return null com.tgpms.web.earlierStage.entity.TaskJournal
     * @author: DESKTOP-I3TG0H3
     * @createDate: 2019-11-27 15:31:51
     */
    TaskJournal selectByPrimaryKey(@Param("id")String id,@Param("journalId")String journalId);

    /**
     * null  updateByPrimaryKeySelective 实现
     * 
     * @param record
     * @return null int
     * @author: DESKTOP-I3TG0H3
     * @createDate: 2019-11-27 15:31:51
     */
    int updateByPrimaryKeySelective(TaskJournal record);

    /**
     * null  updateByPrimaryKey 实现
     * 
     * @param record
     * @return null int
     * @author: DESKTOP-I3TG0H3
     * @createDate: 2019-11-27 15:31:51
     */
    int updateByPrimaryKey(TaskJournal record);
    
    //通过唯一键查询
    TaskJournal selByUniqueKey(@Param("journalId")String journalId);
}